package com.aaa.controller.api;

import com.aaa.aop.annotation.Log;
import com.aaa.entity.CheckItem;
import com.aaa.entity.Role;
import com.aaa.service.RoleService;
import com.aaa.vo.Result;
import com.aaa.vo.RoleVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @BelongsPackage: com.aaa.controller.api
 * @Description:
 * @CreateTime: 2023-03-23  16:56
 * @Author: ql
 */

@RestController
@RequestMapping("system/api/role")
public class ApiRoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("/queryRoleByUserId/{userId}")
    public Result<Map<String,Object>> queryRoleByUserId(@PathVariable Long userId){
        System.out.println("userId = " + userId);
        return roleService.queryRoleByUserId(userId);
    }
    @PostMapping("/confirmRole")
    public Result<String> assignRoles(Long[] roleIds, Long userId){
        return roleService.confirmRole(userId, roleIds);
    }


    @PostMapping("list/{currentPage}/{pageSize}")
    public Result<IPage<Role>> list(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody  RoleVo roleVo
    ) {

        System.out.println("=== === " + currentPage);
        System.out.println("=== === " + pageSize);
        System.out.println("roleVo = " + roleVo);
        return roleService.getByPage(currentPage, pageSize, roleVo);

    }

    @GetMapping("/getById/{id}")
    public Result<Role> getById(@PathVariable Long id){
        return roleService.getById(id);

    }

    @PostMapping("/addOrUpd")
    public Result<String> addOrUpd(@RequestBody Role role){
        return roleService.addOrUpd(role);
    }

    @DeleteMapping("/deleteByIds/{id}")
    @Log(title = "批量删除",business_type = "1")
    public Result<String> deleteByIds(@PathVariable Long[] id){
        System.out.println("=========== " + Arrays.toString(id));
        return roleService.deleteByIds(id);
    }



}
